home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 343_02 / half.c < prev    next >
C/C++ Source or Header  |  1992-04-23  |  4KB  |  141 lines

  1.  
  2.  
  3.        /***********************************************
  4.        *
  5.        *       file d:\cips\half.c
  6.        *
  7.        *       Functions: This file contains
  8.        *          main
  9.        *
  10.        *       Purpose:
  11.        *          This file contains the main calling
  12.        *          routine for a program which shrinks
  13.        *          an image in half (600x600 to a   
  14.        *          300x300).  The output image will 
  15.        *          always be an even multiple of
  16.        *          ROWS and COLS.
  17.        *
  18.        *       External Calls:
  19.        *          gin.c - get_image_name
  20.        *          numcvrt.c - get_integer
  21.        *                      int_convert
  22.        *          tiff.c - read_tiff_header
  23.        *          scale.c - shrink_image_array
  24.        *
  25.        *       Modifications:
  26.        *          25 April 1992 - created
  27.        *
  28.        *************************************************/
  29.  
  30. #include "d:\cips\cips.h"
  31.  
  32.  
  33.  
  34. short the_image[ROWS][COLS];
  35. short out_image[ROWS][COLS];
  36.  
  37. main(argc, argv)
  38.    int argc;
  39.    char *argv[];
  40. {
  41.  
  42.    char     method[80], name[80], name2[80];
  43.    int      count, i, j, length, width,
  44.             il, ie, ll, le;
  45.    struct   tiff_header_struct image_header;
  46.  
  47.    _setvideomode(_TEXTC80); /* MSC 6.0 statements */
  48.    _setbkcolor(1);
  49.    _settextcolor(7);
  50.    _clearscreen(_GCLEARSCREEN);
  51.  
  52.        /***********************************************
  53.        *
  54.        *       Interpret the command line parameters.
  55.        *
  56.        ************************************************/
  57.  
  58.    if(argc < 4 || argc > 4){
  59.     printf(
  60.      "\n"
  61.      "\n usage: half in-file out-file method"
  62.      "\n        method can be Average, Median, Corner"
  63.      "\n");
  64.     exit(0);
  65.    }
  66.  
  67.    strcpy(name,   argv[1]);
  68.    strcpy(name2,  argv[2]);
  69.    strcpy(method, argv[3]);
  70.  
  71.    if(method[0] != 'A' &&
  72.       method[0] != 'a' &&
  73.       method[0] != 'M' &&
  74.       method[0] != 'm' &&
  75.       method[0] != 'C' &&
  76.       method[0] != 'c'){
  77.       printf("\nERROR: Did not enter a valid method"
  78.              "\n       The valid methods are:"
  79.              "\n       Average, Median, Corner");
  80.        printf(
  81.         "\n"
  82.         "\n usage: half in-file out-file method"
  83.         "\n        method can be Average, Median, Corner"
  84.         "\n");
  85.       exit(-2);
  86.    }
  87.  
  88.    il = 1;
  89.    ie = 1;
  90.    ll = ROWS+1;
  91.    le = COLS+1;
  92.  
  93.        /***********************************************
  94.        *
  95.        *       Read the input image header and setup
  96.        *       the looping counters.
  97.        *
  98.        *       Halve the looping counters.
  99.        *
  100.        *       Create the output image.
  101.        *
  102.        ************************************************/
  103.  
  104.    read_tiff_header(name, &image_header);
  105.  
  106.    length = (90 + image_header.image_length)/ROWS;
  107.    width  = (90 + image_header.image_width)/COLS;
  108.    if( (length % 2) != 0) length++;
  109.    if( (width  % 2) != 0) width++;
  110.    length = length/2;
  111.    width  = width/2;
  112.    count  = 1;
  113.  
  114.    image_header.image_length = length*ROWS;
  115.    image_header.image_width  = width*COLS;
  116.    create_allocate_tiff_file(name2, &image_header,
  117.                              out_image);
  118.  
  119.        /***********************************************
  120.        *
  121.        *   Read and shrink each 200x200 area of the
  122.        *   input image and write them to the output
  123.        *   image.
  124.        *
  125.        ************************************************/
  126.  
  127.    count = 1;
  128.    for(i=0; i<length; i++){
  129.       for(j=0; j<width; j++){
  130.          printf("\nrunning %d of %d", count++, length*width);
  131.          shrink_image_array(name, name2, 
  132.                             the_image, out_image,
  133.                             il+i*ROWS*2, ie+j*COLS*2,
  134.                             ll+i*ROWS*2, le+j*COLS*2,
  135.                             il+i*ROWS, ie+j*COLS,
  136.                             ll+i*ROWS, le+j*COLS,
  137.                              2, method);
  138.       }  /* ends loop over j */
  139.    }  /* ends loop over i */
  140. }  /* ends main  */
  141.